<?php
class ModelsModel extends FW24H_Model {
	var $tableName = 'vma2008_models';
	var $_primaryKey = 'model_id';

	function randomModels( $p_limit = 10) {
		return $this->find( 'model_active="YES"', 'model_id, model_fullname, model_code', 'RAND()', $p_limit);
	}
	
	// lay diem nguoi mau cao nhat
	function getHighest() {
		// lay session dang hoat dong
		$f_sql = 'SELECT MAX(vote_points) as Highest FROM vma2008_model_votes, vma2008_sessions WHERE vma2008_sessions.session_id=vma2008_model_votes.session_id AND session_active="YES"';
		return $this->execute( $f_sql);
	}

	function getModel( $id) {
		$f_model = $this->get( $id);

		$objImage = new FW24H_Model( 'vma2008_model_images', 'model_image_id');
		$objImage->_cache = true;
		$objImage->_cacheTime = 1800;
		$f_model['images'] = $objImage->find( 'model_id='.$id, 'model_image_filename');

		return $f_model;
	}

	function getByRegion( $p_region='1') {
		return $this->find( 'model_locate_id='.$p_region, 'model_fullname, model_id, model_code');
	}

	function getBySex( $p_sex = 'FEMALE') {
		return $this->find( 'model_sex='.$p_sex, 'model_fullname, model_id, model_code');
	}
}


